package com.smart.springaiopen.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Guoxinyu
 * @description: TODO
 * @date 2025/5/28 9:31
 * @email gxy06x@qq.com
 */
@RestController
public class ChatClientController {

    private static final Logger log = LoggerFactory.getLogger(ChatClientController.class);
    private final ChatClient chatClient;

    //手动注入
    public ChatClientController(ChatClient.Builder chatBuilder) {
        this.chatClient = chatBuilder.build();
    }

    @GetMapping("/ai/chat")
    public String chat(@RequestParam(value = "message", defaultValue = "hello")  String message) {
        String content = chatClient.prompt() //提示词
                .user(message)//用户输入信息
                .call() //调用
                .content();//获取结果
        log.info("content:{}", content);
        return content;
    }
}
